import 'package:flutter/material.dart';
import '../model/post.dart';
import './posts_show.dart';

class ListViewDemo extends StatelessWidget {
  Widget _listItemBuilder(BuildContext context, int index) {
    return Container(
        color: Colors.white,
        margin: EdgeInsets.all(10),
        child: Stack(
          children: <Widget>[
            Column(
              children: <Widget>[
                Image.network(posts[index].imageUrl),
                SizedBox(
                  height: 10,
                ),
                Text(
                  posts[index].author,
                  style: TextStyle(
                    color: Colors.grey,
                    fontWeight: FontWeight.bold,
                    fontSize: 14,
                  ),
                ),
                SizedBox(
                  height: 10,
                ),
                Text(
                  posts[index].title,
                  style: TextStyle(
                    color: Colors.green,
                    fontSize: 20,
                  ),
                ),
                SizedBox(
                  height: 10,
                )
              ],
            ),
            Positioned.fill(
              child: Material(
                color: Colors.transparent,
                child: InkWell(
                  splashColor: Colors.white.withOpacity(0.4),
                  highlightColor: Colors.white.withOpacity(0.2),
                  onTap: () {
                    Navigator.push(
                        context,
                        MaterialPageRoute(
                            builder: (context) => PostShowDemo(
                                  post: posts[index],
                                )));
                  },
                ),
              ),
            )
          ],
        ));
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return ListView.builder(
      itemCount: posts.length,
      itemBuilder: _listItemBuilder,
    );
  }
}
